import type { Category } from "@/types/Category";
import type { Pagination, XtxResponse } from "@/types/Response";
import XtxRequestManager from "@/utils/XTXRequestManager";
import type { Goods, GoodsRequestParams } from "@/types/Goods"

export class CategoryAPI {
    // 获取导航分类数据
    static getCategories() {
        return XtxRequestManager.instance.request<XtxResponse<Category[]>>({
            url: "/home/category/head",

        });
    }

    //根据一级分类id获取一级分类具体信息
    static getTopCategoryById(id: string) {
        return XtxRequestManager.instance.request<XtxResponse<Category>>({
            url: "/category",
            params: { id }
        })
    }

    //根据二级分类id获取该分类下的商品的筛选条件
    static getSubCategoryFilters(id: string) {
        return XtxRequestManager.instance.request<XtxResponse<Category>>({
            url: "/category/sub/filter",
            params: { id }
        })
    }
    // 获取商品列表 请求参数中二级分类id是必传的 所以此处将它设置为单独的参数
    static getCategoryGoods(
        categoryId: GoodsRequestParams["categoryId"],
        reqParams?: Partial<Omit<GoodsRequestParams, "categoryId">>
    ) {
        return XtxRequestManager.instance.request<
            XtxResponse<Pagination<Goods>>,
            Partial<GoodsRequestParams>
        >({
            url: "/category/goods",
            method: "post",
            data: {
                categoryId, ...reqParams
            }
        })
    }
}